﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using forum.Data;
using System.Net.Sockets;
using System.Text;
using forum.ApplicationCode;
using System.Threading;

namespace forum
{
    public partial class forumWelcome : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Reload the page, not from broswer's cache
            Response.AppendHeader("Cache-Control", "no-store");



            Session["addSubForumName"] = null;
             using (forumDataContext data = new forumDataContext())
                {

                    lvSubForumList.DataSource = data.sp_GetSubForumList();
                    lvSubForumList.DataBind();


                }


                if(Session["last"]==null)
                    Session["last"] = 5;

          
        }

        protected void lvSubForumList_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            using (forumDataContext data = new forumDataContext())
            {
                int forumId = ((sp_GetSubForumListResult)DataBinder.GetDataItem(e.Item)).subForumId;

                Label numOf = e.Item.FindControl("lblNumOfMessages") as Label;
                int numOfPosts = data.sp_GetSubForumNumberOfPosts(forumId).FirstOrDefault().numOfPosts.Value; 
                int numOfThreads = data.sp_GetSubForumNumberOfThreads(forumId).FirstOrDefault().numOfThreads.Value;
                int total = numOfPosts + numOfThreads;
                numOf.Text = "(" + total.ToString() + ")";


            }

        }



        

    }
}